package com.course.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.course.bean.QueryTo;
import com.course.delegate.QueryMgrDelegate;
import com.course.exception.DataNotFoundException;
import com.course.util.UtilConstants;



public class SolutionAction extends HttpServlet {

	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String path="";
		Vector<QueryTo> vqb=null;

		  try{
			   int qid=Integer.parseInt(request.getParameter("qid"));
			  try{
			      vqb= new QueryMgrDelegate().getQueriesAt(qid);
			  }catch (DataNotFoundException e) {
				e.printStackTrace();
			}
			  System.out.println("in Action class vcb..........."+vqb);
			  if(!vqb.isEmpty())
			  {
				  request.setAttribute("Querysolution", vqb);
				  request.setAttribute("status", UtilConstants._STUDENT_QUERY_INFO);
				  path=UtilConstants._SOLUTION_HOME;
				 }
			  else {
				  request.setAttribute("status", UtilConstants._NO_QUERY);
				  path=UtilConstants._SOLUTION_HOME;}
			  }
		  catch (Exception e) {
			  request.setAttribute("status", UtilConstants._NO_QUERY);
			  path=UtilConstants._SOLUTION_HOME;
			  e.printStackTrace();}
		   RequestDispatcher rd=request.getRequestDispatcher(path);
			rd.forward(request,response);}

}
